﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using WpfAppDemo.command;

namespace WpfAppDemo.dataContext
{
    internal class MyDataContext : NotifyPropertyChangedBase
    {
        public ICommand ShowTips { get; set; }

        public ICommand ChangeName { get; }

        private string _userName;

        public string UserName
        {

            get => _userName;
            set
            {
                _userName = value;
                /*
                 * 
                    在Command中直接更改数据不会导致 更新后的数据被重新渲染
                需要发布事件来通知更新
                 */
                onChange();
                //PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(nameof(UserName)));
            }
        }

        public MyDataContext()
        {
            UserName = "会是谁呢";
            ShowTips = new DelegatingCommand(ShowMessage);
            ChangeName = new DelegatingCommand(() =>
            {

                UserName = "别的人";
            });
        }




        private void ShowMessage()
        {
            UserName = "罗俊华";
            MessageBox.Show("成功的收到了一条提示");
        }
    }
}
